import requests
from py05_register_api import RegisterApi


class TestRregisterApi(object):
    def setup_class(self):
        self.tpshop = RegisterApi()

    def setup(self):
        self.session = requests.Session()
        self.tpshop.get_verify_code(self.session)

    def test01_register_success(self):
        req_body = {"username": "13811118882", "verify_code": "8888", "password": "123456", "password2": "123456"}
        resp = self.tpshop.register(self.session, req_body)
        print("注册成功", resp)

        assert 200 == resp.status_code
        assert 1 == resp.json().get("status")
        assert "成功" in resp.json().get("msg")

    def test02_mobile_exist(self):
        req_body = {"username": "13811118888", "verify_code": "8888", "password": "123456", "password2": "123456"}
        resp = self.tpshop.register(self.session, req_body)
        print("账号(手机号)已存在", resp)

        assert 200 == resp.status_code
        assert -1 == resp.json().get("status")
        assert "已注册" in resp.json().get("msg")

    def test03_2_pwd_input_inconformity(self):
        req_body = {"username": "13811118881", "verify_code": "8888", "password": "123456", "password2": "123123"}
        resp = self.tpshop.register(self.session, req_body)
        print("两次输入密码不一致", resp)

        assert 200 == resp.status_code
        assert -1 == resp.json().get("status")
        assert "两次密码不一致" in resp.json().get("msg")
